package fr.vahren.dotastrat.gui;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.trolltech.qt.core.QSize;
import com.trolltech.qt.core.Qt.AspectRatioMode;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QPixmap;

public class D2SMapWidget extends QLabel {

	private QPixmap mapImage;
	private List<D2SZoneWidget> zones;

	private static final List<List<Integer>> zonesPositions = new ArrayList<>();

	static {
		zonesPositions.add(Arrays.asList(50, 145));
		zonesPositions.add(Arrays.asList(115, 70));
		zonesPositions.add(Arrays.asList(230, 75));
		zonesPositions.add(Arrays.asList(355, 70));
		zonesPositions.add(Arrays.asList(465, 80));
		zonesPositions.add(Arrays.asList(555, 90));
		zonesPositions.add(Arrays.asList(645, 105));
		zonesPositions.add(Arrays.asList(705, 40));
		zonesPositions.add(Arrays.asList(145, 180));
		zonesPositions.add(Arrays.asList(225, 135));
		zonesPositions.add(Arrays.asList(350, 145));
		zonesPositions.add(Arrays.asList(510, 215));
		zonesPositions.add(Arrays.asList(585, 175));
		zonesPositions.add(Arrays.asList(675, 205));
		zonesPositions.add(Arrays.asList(50, 265));
		zonesPositions.add(Arrays.asList(160, 240));
		zonesPositions.add(Arrays.asList(310, 220));
		zonesPositions.add(Arrays.asList(370, 250));
		zonesPositions.add(Arrays.asList(460, 290));
		zonesPositions.add(Arrays.asList(585, 270));
		zonesPositions.add(Arrays.asList(680, 295));
		zonesPositions.add(Arrays.asList(55, 345));
		zonesPositions.add(Arrays.asList(130, 320));
		zonesPositions.add(Arrays.asList(220, 365));
		zonesPositions.add(Arrays.asList(285, 295));
		zonesPositions.add(Arrays.asList(405, 350));
		zonesPositions.add(Arrays.asList(580, 355));
		zonesPositions.add(Arrays.asList(680, 370));
		zonesPositions.add(Arrays.asList(55, 420));
		zonesPositions.add(Arrays.asList(140, 440));
		zonesPositions.add(Arrays.asList(285, 420));
		zonesPositions.add(Arrays.asList(345, 383));
		zonesPositions.add(Arrays.asList(420, 445));
		zonesPositions.add(Arrays.asList(510, 415));
		zonesPositions.add(Arrays.asList(600, 450));
		zonesPositions.add(Arrays.asList(675, 475));
		zonesPositions.add(Arrays.asList(65, 495));
		zonesPositions.add(Arrays.asList(190, 545));
		zonesPositions.add(Arrays.asList(230, 480));
		zonesPositions.add(Arrays.asList(300, 530));
		zonesPositions.add(Arrays.asList(410, 510));
		zonesPositions.add(Arrays.asList(530, 540));
		zonesPositions.add(Arrays.asList(530, 480));
		zonesPositions.add(Arrays.asList(665, 575));
		zonesPositions.add(Arrays.asList(45, 565));
		zonesPositions.add(Arrays.asList(130, 590));
		zonesPositions.add(Arrays.asList(390, 605));
		zonesPositions.add(Arrays.asList(550, 615));
		zonesPositions.add(Arrays.asList(25, 690));
		zonesPositions.add(Arrays.asList(75, 635));
		zonesPositions.add(Arrays.asList(160, 675));
		zonesPositions.add(Arrays.asList(245, 675));
		zonesPositions.add(Arrays.asList(355, 680));
		zonesPositions.add(Arrays.asList(460, 680));
		zonesPositions.add(Arrays.asList(600, 680));
		zonesPositions.add(Arrays.asList(595, 515));
		zonesPositions.add(Arrays.asList(250, 210));
	}

	public D2SMapWidget() {
		// create a PixMap to display the map
		QPixmap map = new QPixmap("res/map.png");
		mapImage = map.scaled(new QSize(800, 800),
				AspectRatioMode.KeepAspectRatio);
		setFixedSize(800, 800);
		setStyleSheet("background-color: rgba(255, 200, 200, 90);");
		setPixmap(mapImage);
		zones = new ArrayList<>();

		for (int i = 0; i < zonesPositions.size(); i++) {
			zones.add(new D2SZoneWidget(zonesPositions.get(i).get(0),
					zonesPositions.get(i).get(1), this, i + 1));
		}

	}

	/**
	 * Gets the zone from id (starts from 1).
	 * 
	 * @param id
	 * @return The zone.
	 */
	public D2SZoneWidget getZone(long id) {
		return zones.get((int) (id - 1));
	}

	/**
	 * @return the zones
	 */
	public List<D2SZoneWidget> getZones() {
		return zones;
	}

	/**
	 * @param zones
	 *            the zones to set
	 */
	public void setZones(List<D2SZoneWidget> zones) {
		this.zones = zones;
	}

}
